package boot.spring.controller;

import boot.spring.entity.Users;
import boot.spring.entity.Usersrole;
import boot.spring.service.UsersService;
import boot.spring.service.UsersroleService;
import boot.spring.util.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/UsersController")
@RestController
public class UsersController {
    /*引用UsersService业务层*/
    @Autowired
    private UsersService usersService;

    /*引用usersrole的业务层*/
    @Autowired
    private UsersroleService usersroleService;

    //@RequiresPermissions("user:list")
    @GetMapping("/UserConAll")/*分页获取所有数据  根据多条件(用户名、起止时间、是否锁定、排序)*/
    public Result UserConAll(Integer page, Integer limit,
                             String uname, String begintime,
                             String endtime, String iflock,
                             String weight,String token) {
        return usersService.UserSerAll(page,limit,uname,begintime,endtime,iflock,weight);
    }

    //@RequiresPermissions("user:insert")
    @PostMapping("/UserConAdd")/*创建用户【用户名不能重复】*/
    public Result UserConAdd(Users add,String token){
        return usersService.UserSerAdd(add);
    }

    //@RequiresPermissions("user:Unlock")
    @RequestMapping("/UserConUnlocklock") /*解锁锁定用户*/
    public Result UserConUnlocklock(Users up){
        return usersService.UserSerUnlocklock(up);
    }

    //@RequiresPermissions("user:UserRoleAdd")
    @GetMapping("/UserRoleAdd")/*为当前用户添加角色*/
    public  Result UserRoleAdd(Usersrole uradd){
        return usersroleService.UrSerAdd(uradd);
    }

    //@RequiresPermissions("user:UserRoleRemove")
    @GetMapping("/UserRoleRemove")/*为当前用户移除角色*/
    public  Result UserRoleRemove(Usersrole urremove){
        return usersroleService.UrSerRemove(urremove);
    }

    //@RequiresPermissions("user:UserConUnup")
    @RequestMapping("/UserConUnup") /*修改用户信息*/
    public Result UserConUnup(Users up){
        return usersService.UserSerUp(up);
    }

    //@RequiresPermissions("user:UserConDel")
    @RequestMapping("/UserConDel") /*删除用户信息*/
    public Result UserConDel(Users del){
        return usersService.UserSerDel(del);
    }

    //@RequiresPermissions("user:UserConPwdUp")
    @RequestMapping("/UserConPwdUp") /*重置密码*/
    public Result UserConPwdUp(Users pwdup){
        return usersService.UsersSerPwdUp(pwdup);
    }

}
